import java.io.*;
import java.net.*;
import java.lang.Thread;

public class KunalServer{
	
  	String SERVER_HOST = new String("localhost");
	int SERVER_PORT = 0;
	ServerSocket myServerSocket;
	Socket mySocket;
	BufferedReader mySocketReader,myInputReader;
	PrintWriter mySocketWriter;
	
	public KunalServer() throws Exception
	{
		//Initialises all the varibales that would be required...

		//System.out.println("Please enter Server port # : ");
		//myInputReader = new BufferedReader( new InputStreamReader (System.in));
		//SERVER_PORT = Integer.parseInt( new String( myInputReader.readLine() ));
	    SERVER_PORT = 15687;
	    myServerSocket = new ServerSocket( SERVER_PORT );

		
		
	}// End Constructor KunalServer()
	
	public void acceptLoginRequest() throws Exception
	{
		mySocket = new Socket();
		System.out.println("Accepting Login Request  :");
		mySocket = myServerSocket.accept();
		System.out.println("New Connection : " + mySocket);
		mySocketReader = new BufferedReader(new InputStreamReader( mySocket.getInputStream()));
	    
	
        try{
			String loginName = new String(mySocketReader.readLine());
			if(loginName != null)
			{		
	          System.out.println(loginName + " Connected");
	        }else{}

	    	}catch( IOException e){}
	         catch( NullPointerException ne){}
		
		
	}// End acceptLoginRequest()
	
	public void sendServicesToClient() throws Exception
	{
	  mySocketWriter = new PrintWriter(new OutputStreamWriter( mySocket.getOutputStream()));
	  String menu =  "*** Welcome to Live Video Streaming Server ***\n\n"
	                + "   Enter Service Number from the Menu ......\n"
	                + "   1. Create an Account ..\n"
	                + "   2. Existing Users Login ..\n"
	                + "   3. Get List of Valid Accounts\n"          
	                + "   4. List of Currently Online Users ..\n"
	                + "   5. Join Group Chat Room ..\n"
	                + "   6. \n"
	                + "Select one of the options and Hit Enter .\n"
	                + "flagLastLine\n";	
	 //System.out.println(menu);
	 mySocketWriter.println(menu);
	 mySocketWriter.flush();	
		
		
	}// End sendMenuToClient()
	
	public void getClientRequest() throws Exception
	{
	   int requestNumber = Integer.parseInt(new String (mySocketReader.readLine()));
	   System.out.println("Client Requests for service number : " + requestNumber);	
		
	}// End getClientRequest()
	
	public static void main(String args[]) throws Exception
	{
		KunalServer myServer = new KunalServer();
		myServer.acceptLoginRequest();
		myServer.sendServicesToClient();
		myServer.getClientRequest();
        
		
	}// End main
	
}// End class server()
